﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace QuanLyThuoc.DAL
{
   public class ToaThuocDAL:KetNoiDAL
    {
       public DataTable SelectAll_ToaThuoc()
       {
           SqlCommand cmd = new SqlCommand("SelectAll_ToaThuoc",Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public DataTable DemSoLuong_ToaThuoc()
       {
           SqlCommand cmd = new SqlCommand("DemSoLuongToa", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public DataTable SearchToaCondition(string keyword)
       {
           SqlCommand cmd = new SqlCommand("SelectToaThuocByCondition", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@keyword", keyword);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public DataTable SelectID_ToaThuoc(string IDToa)
       {
           SqlCommand cmd = new SqlCommand("SelectAll_ToaThuoc", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@IDToa", IDToa);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public int InsertToaThuoc(string IdToa, int IDThuoc,int IDBN, string HoTen, string NamSinh, string Gioi, string DiaChi, string SoDT, string ChanDoan, int SoNgayUong, string NgayTK)
       {
           
               SqlCommand cmd = new SqlCommand("Insert_ToaThuoc", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@IDToa", IdToa);
               cmd.Parameters.AddWithValue("@IDBN", IDBN);
               cmd.Parameters.AddWithValue("@IDThuoc", IDThuoc);
               cmd.Parameters.AddWithValue("@TenBN", HoTen);
               cmd.Parameters.AddWithValue("@NamSinh", NamSinh);
               cmd.Parameters.AddWithValue("@Gioi", Gioi);
               cmd.Parameters.AddWithValue("@DiaChi", DiaChi);
               cmd.Parameters.AddWithValue("@SoDT", SoDT);
               cmd.Parameters.AddWithValue("@ChanDoan", ChanDoan);
               cmd.Parameters.AddWithValue("@SoNgayUong", SoNgayUong);
               cmd.Parameters.AddWithValue("@NgayTK", NgayTK);
             return  cmd.ExecuteNonQuery();
          
       }
       public int UpdateToaThuoc(string IdToa, int IDBN, int IDThuoc, string HoTen, string NamSinh, string Gioi, string DiaChi, string SoDT, string ChanDoan, int SoNgayUong, string NgayTK)
       {
           
               SqlCommand cmd = new SqlCommand("Update_ToaThuoc", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@IDToa", IdToa);
               cmd.Parameters.AddWithValue("@IDBN", IDBN);
               cmd.Parameters.AddWithValue("@IDThuoc", IDThuoc);
               cmd.Parameters.AddWithValue("@HoTen", HoTen);
               cmd.Parameters.AddWithValue("@NamSinh", NamSinh);
               cmd.Parameters.AddWithValue("@Gioi", Gioi);
               cmd.Parameters.AddWithValue("@DiaChi", DiaChi);
               cmd.Parameters.AddWithValue("@SoDT", SoDT);
               cmd.Parameters.AddWithValue("@ChanDoan", ChanDoan);
               cmd.Parameters.AddWithValue("@SoNgayUong", SoNgayUong);
               cmd.Parameters.AddWithValue("@NgayTK", NgayTK);
              return cmd.ExecuteNonQuery();
         
       }
       public int Delete_ToaThuoc(string IDToa)
       {
          
               SqlCommand cmd = new SqlCommand("Delete_ToaThuoc", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@IDToa", IDToa);
            return   cmd.ExecuteNonQuery();
          
       }
    }
}
